<?php
/**
 * User: 五哥派
 * Date: 2024/6/30
 * Tel(同WX): 17335592719
 */
namespace app\admin\model\store;

use app\admin\model\Base;

class SpecsValue extends Base{

    protected $name = 'store_specs_value';

    public function specs(){
        return $this->belongsTo('Specs','specs_id');
    }

    public function findDataByID($id, $field = ''){
        return self::with(['specs'])->where('id',$id)->field($field)->find();
    }

    /**
     * getBySpecsId
     * @param $specsId
     * @return array
     */
    public function getBySpecsId($specsId) {
        try {
            $result = $this->getNormalBySpecsId($specsId, "id,name");
        }catch (\Exception $e) {
            return [];
        }
        $result = $result->toArray();
        return $result;
    }

    public function getNormalBySpecsId($specsId, $field="*") {
        $where = [
            "specs_id" => $specsId,
            "status" => 1,
        ];

        $res = $this->where($where)
            ->field($field)
            ->select();
        return $res;
    }



    public function getNormalInIds($ids) {
        return $this->whereIn("id", $ids)
            ->where("status", "=", 1)
            ->select();
    }

}